package com.dh.service.impl;

import com.dh.core.config.Constant;
import com.dh.entity.UserPrep;
import com.dh.repository.PrepRepository;
import com.dh.service.PrepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class PrepServiceImpl implements PrepService {

    @Autowired
    private PrepRepository prepRepository;

    public Page<UserPrep> page(PageRequest pageRequest) {
        return prepRepository.findByDeleted(Constant.NOT_DELETE, pageRequest);
    }

    @Override
    public UserPrep get(Long prepId) {
        return prepRepository.findOne(prepId);
    }


    public void delete(Long userId) {
        //        UserPrep account = prepRepository.findOne(userId);
        //        account.setDeleted(Constant.DELETE);
        //        prepRepository.save(account);
        prepRepository.delete(userId);
    }

    @Override
    public void create(UserPrep prep) {
        prepRepository.save(prep);
    }

    @Override
    public void update(UserPrep prep) {
        prepRepository.save(prep);
    }

    @Override
    public UserPrep findByNoAndDeleted(String no, byte deleted) {
        return prepRepository.findByNoAndDeleted(no, deleted);
    }

}
